
	use "${source}online_survey_dataset.dta", clear 
	
	
**** reshape data in long format: 2 observations per individual 
										
reshape long spouse_age  spouse_birthplace spouse_education  spouse_characteristics probability_marriage, ///
 i( code) j(scenario) string 
	

	egen id= group(code)
	gen US= scenario=="_us"

	gen    first_scenario=0 
	replace   first_scenario =1  if scenario=="_us" & orderb==1
	replace first_scenario = 1 if scenario=="_mex" & orderb==0 

	label var  first_scenario "Scenario: asked first"
	label var US "Scenario: migration to U.S."

	
	*dependent 
	foreach v in spouse_age  spouse_birthplace spouse_education    {
	gen `v'_4= `v'==4 if `v'!=.
	}
	
	gen likely_married= inlist(probability_marriage ,4,5)
	gen sum_dontknow= spouse_age_4 +  spouse_birthplace_4 + spouse_education_4
	gen anydontknow= sum_dontknow>0  if sum_dontknow!=. 
	gen insegura_char= inlist( spouse_characteristics ,1,2,3) 
	
	label var probability_marriage  "proba married in 10y (1-5 scale)"
	label var spouse_characteristics "sp other charac certainty (1-5 scale)"
	label var likely_married "likely ($>$ 60\%) to be married in 10y (bin)"
	
	label var sum_dontknow "nb don't know (spouse age, edu, birthplace) "  
	label var  anydontknow  "At least one don't know about spouse (bin)"  
	label var  insegura_char "unsure about sp other characteristics (bin)"  
	
	
	
global option varlabels tex plain fragment bdec() se starloc(1) starlevels(10 5 1) nocenter ///
		summstat(r2\N) summtitle("R^2" \"Observations") summdec(3 0) blankrows 
	
	global model_3	"Controls:", ""\  "Scenario order in Quest.", "Yes" \"Individual FE", "Yes"

	global Y  probability_marriage likely_married sum_dontknow anydontknow  spouse_characteristics insegura_char

	outreg,clear(dep_final)
	
foreach outcome in $Y {		
	
		local labout : variable label `outcome'			

		tempvar samplee
		g `samplee' = 1
		qui su `outcome' if `samplee'==1 & US==0 
		local av: di %4.3f r(mean)	
			
			
		qui  reghdfe  `outcome' US first_scenario   if `samplee' ==1 , absorb(id) cluster(id) 	
		 outreg, merge(dep_final)  keep(US ) ctitle("Dep:","`labout'" )  addrows( "","" \  "Average outcome in control group", `av'   \  "${model_3}")  ${option} 	
						
	}
	
	outreg using "${result}Table5.smcl", replace title(Table 5: Expectations about marriage and future spouse in two scenarios: migrating versus staying) replay(dep_final) ${option} 
	
	